package com.yonyou.pmclouds.workflow.service.rmiimpl;

import com.yonyou.pmclouds.basecom.billstatus.BillStatusConst;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.entity.ProcessCallbackVO;
import com.yonyou.pmclouds.workflow.entity.ProcessDefinitionVO;
import com.yonyou.pmclouds.workflow.mapper.ProcessDefinitionMapper;
import com.yonyou.pmclouds.workflow.service.rmiitf.IFlowApprove;
import com.yonyou.pmclouds.workflow.service.rmiitf.ProcessCallbackService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;

public class ProcessCallbackServiceImp implements ProcessCallbackService {

    @Autowired
    private ProcessDefinitionMapper processDefinitionMapper;
    @Autowired
    private IFlowApprove flowApprove;


    @Override
    public boolean completeCallBack(ProcessCallbackVO callbackVO) throws BusinessException{

        String processDefinitionKey = callbackVO.getProcessDefinitionKey();
        ProcessDefinitionVO[] procDefVOs = processDefinitionMapper.queryByProcessKey(processDefinitionKey);

        if(ArrayUtils.isEmpty(procDefVOs))
            throw new BusinessException("没有查到对应的流程配置信息");

        String billType = procDefVOs[0].getBillType();
        String pkBill = callbackVO.getBusinessKey();
        String userid = callbackVO.getUserId();

        boolean result = flowApprove.approve(pkBill,billType, BillStatusConst.COMMON_APPROVED_STATUS);

        return result;
    }
}
